* ----------------------------------------------------------------------------- *
* Natural Resource Rents, Local Taxes, and Government Performance: Evidence from
* Colombia
* By: Luis R. Martinez
* Name: 30-appendix.do
* Description: This do file produces all the tables and figures in the online appendix.
*
* ----------------------------------------------------------------------------- *

clear all 
cls 

*explanatory vars for reduced-form regs
global rf_log post_update0610any lroy
global rf_level post_update0610any roy_ipoil
global rf_port post_update0610any roilpcravg_iprcopr
global rf_period post_sum lr_oilpcr00_prcopr

*explanatory vars for iv regs
global iv_log (ly_tax_pred_pcr ly_k_rega_pcr = post_update0610any lroy )
global iv_port (y_tax_pred_pcr y_k_rega_pcr = post_update0610any roilpcravg_iprcopr)
global iv_level (y_tax_pred_pcr y_k_rega_pcr = post_update0610any roy_ipoil)
global iv_tax_level (y_tax_pred_pcr = post_update0610any)
global iv_roy_level (y_k_rega_pcr = roy_ipoil)
global iv_period (ly_tax_pred_pcr ly_k_rega_pcr = post_sum lr_oilpcr00_prcopr)
global ols_level y_tax_pred_pcr y_k_rega_pcr
global ols_period ly_tax_pred_pcr ly_k_rega_pcr 

*sample restrictions: (i) 2005-2011, (ii) only IGAC, (iii) valid: not missing key vars 
global if if year>=2005&year<=2011&valid==1
global if_period if igac==1&corregimiento==0

*fixed effects
global fe absorb(codmpio i.year#i.coddepto)
global fe_mm absorb(i.codmpio#i.term i.year#i.coddepto) 
global fe_initial absorb(codmpio i.year#c.\`var' i.year#i.coddepto)
global fe_period absorb(codmpio i.coddepto#i.period)
global fe_category absorb(codmpio i.year#i.coddepto#i.category)

*two-way clustering of standard errors
global cluster cluster(codmpio dpt_year) 
global cluster_muni cluster(codmpio) 
global cluster_period cluster(codmpio dpt_period) 

*First-stage F-stats
global F_tax local F_tax: di %4.2fc e(first)[8,1]
global F_roy local F_roy: di %4.2fc e(first)[8,2]
global F_roy1 local F_roy: di %4.2fc e(widstat)

*p-values of difference in IV estimates
global test_log	test ly_tax_pred_pcr = ly_k_rega_pcr
global test_level test y_tax_pred_pcr = y_k_rega_pcr
global p_val local p_val: di %4.3fc r(p)

*additional stats for IV regs
global add_iv addtext(F-stat tax, \`F_tax', F-stat royalties,  \`F_roy', p-value H0:tax=royalties,"\`p_val'")
global add_iv_tax addtext(F-stat, \`F_tax')
global add_iv_roy addtext(F-stat, \`F_roy')
global add_ols addtext(p-value H0:tax=royalties,"\`p_val'")


*-------------------------------------------------------------------------------*
**# APPENDIX A:
*-------------------------------------------------------------------------------*

* Table A1: --------------------------------------------------------------------

** Panel A, B, and C;
use "${dpwork}\ESTIMATIONS.dta", clear

est clear  // clear the est locals

foreach x of varlist consultas0_pc low_weight_pc {
	replace `x'=`x'*100
}

reghdfe lcnbas $rf_level ${if}, $fe $cluster   

#d ;

local vars_main y_tax_pred_pcr y_k_rega_pcr y_total_pcr g_total_pcr i_pcr 
	  post_update0610any roy_ipoil cnbas cobrs irca Dcnbas100 Dcobrs100 Dirca05 
	  consultas0_pc low_weight_pc cob01_bcg cob01_dpt cob01_pol tmi 
	  defunciones01_pc eda_ira01_pc ; 

estpost tabstat `vars_main' $if&e(sample), c(stat) stat(mean sd min max n);

esttab using "${dpappendix}\A-data\01-tableA1.tex", replace 
	cells("mean(fmt(%4.2fc)) sd(fmt(%4.2fc)) min max count") 
	nonumber 
	nomtitle 
	nonote 
	noobs 
	booktabs 
	collabels("Mean" "SD" "Min" "Max" "N");


** Panel D:;
use "${dpwork}\ESTIMATIONS-TERM.dta", clear;

reghdfe alcalde $rf_period ${if_period}, $fe_period $cluster_period; 	

estpost tabstat alcalde alcalde_sum alcalde_1 alcalde_2 alcalde_3 
	$if_period & e(sample), 
	c(stat) 
	stat(mean sd min max n);

esttab using "${dpappendix}\A-data\01-tableA1.tex", append 
	cells("mean(fmt(%4.2fc)) sd(fmt(%4.2fc)) min max count") 
	nonumber 
	nomtitle 
	nonote 
	noobs 
	booktabs 
	collabels("Mean" "SD" "Min" "Max" "N");
#d cr

*-------------------------------------------------------------------------------*
**# APPENDIX B:
*-------------------------------------------------------------------------------*

* Figure B1: ------------------------------------------------------------------- 

use "${dpwork}\ESTIMATIONS.dta", clear

macro drop files 

foreach x of varlist cnbas tmi cobrs acu_tot alc_tot{
	mean `x' ${if}&year==2005
	parmest,saving("${dptemp}\sumstats_`x'_full", replace) idstr(full)			///
			flist(files)
	
	mean `x' ${if}&year==2005&updater0610any ==1
	parmest,saving("${dptemp}\sumstats_`x'_cad", replace) idstr(cad) 			///
			flist(files)
	
	mean `x' ${if}&year==2005&r_oilpcravg>0&r_oilpcravg!=.
	parmest,saving("${dptemp}\sumstats_`x'_oil", replace) idstr(oil) 			///
			flist(files)
}

mean irca ${if}&year==2007
parmest,saving("${dptemp}\sumstats_irca_full", replace) idstr(full) flist(files)

mean irca ${if}&year==2007&updater0610any ==1
parmest,saving("${dptemp}\sumstats_irca_cad", replace) idstr(cad) flist(files)

mean irca ${if}&year==2007&r_oilpcravg>0&r_oilpcravg!=.
parmest,saving("${dptemp}\sumstats_irca_oil", replace) idstr(oil) flist(files)

foreach x of varlist Dcnbas100 Dtmi165 Dcobrs100 Dacutot915 Dalctot855 {
	mean `x' ${if}&year==2005
	parmest,saving("${dptemp}\sumstats_`x'_full", replace) idstr(full) 			///
			flist(files)
	
	mean `x' ${if}&year==2005&updater0610any ==1
	parmest,saving("${dptemp}\sumstats_`x'_cad", replace) idstr(cad) 			///
			flist(files)
	
	mean `x' ${if}&year==2005&r_oilpcravg>0&r_oilpcravg!=.
	parmest,saving("${dptemp}\sumstats_`x'_oil", replace) idstr(oil) 			///
			flist(files)
}

mean Dirca05 ${if}&year==2007
parmest,saving("${dptemp}\sumstats_Dirca05_full", replace) idstr(full) 			///
		flist(files)

mean Dirca05 ${if}&year==2007&updater0610any ==1
parmest,saving("${dptemp}\sumstats_Dirca05_cad", replace) idstr(cad) 			///
		flist(files)

mean Dirca05 ${if}&year==2007&r_oilpcravg>0&r_oilpcravg!=.
parmest,saving("${dptemp}\sumstats_Dirca05_oil", replace) idstr(oil) 			///
		flist(files)

preserve

clear

foreach x of global files {
	append using "`x'" 
}

gen target =_n>=19
gen temp=_n
gen temp1=0
replace temp1=1 if parm!=parm[_n-1]&target==target[_n-1]
bysort target (temp): gen temp2=_n
bysort target (temp): gen temp3=sum(temp1)
gen id=temp2+temp3
drop temp*
sort target id

gen meta = 100 if parm=="cnbas"|parm=="cobrs"
replace meta =16.5 if parm=="tmi"
replace meta =91.5 if parm=="acu_tot"
replace meta =85.5 if parm=="alc_tot"
replace meta =5 if parm=="irca"

#d ;

** Panel A;

twoway 	(bar estimate id if idstr=="full", barwidth(0.9) fintensity(75)) 
		(bar estimate id if idstr=="cad", barwidth(0.9) fintensity(15)) 
		(bar estimate id if idstr=="oil", barwidth(0.9) fintensity(55)) 
		(rcap min95 max95 id,color(black)) 
		(line meta id if parm=="cnbas",lcolor(red) lwidth(medium)) 
		(line meta id if parm=="tmi",lcolor(red) lwidth(medium)) 
		(line meta id if parm=="cobrs",lcolor(red) lwidth(medium)) 
		(line meta id if parm=="acu_tot",lcolor(red) lwidth(medium)) 
		(line meta id if parm=="alc_tot",lcolor(red) lwidth(medium)) 
		(line meta id if parm=="irca",lcolor(red) lwidth(medium)) 
		(pcarrowi 95 2 100 2,color(red)) 
		(pcarrowi 21.5 6 16.5 6,color(red)) 
		(pcarrowi 95 10 100 10,color(red)) 
		(pcarrowi 86.5 14 91.5 14,color(red)) 
		(pcarrowi 80.5 18 85.5 18,color(red)) 
		(pcarrowi 10 22 5 22,color(red)) 
		if target==0, 
		ylabel(0(20)100,angle(horizontal)) 
		ytitle(Mean [95% confidence interval])
		xtitle("")
		xlabel(2 `" `"Educational"' `"enrolment"' `"(%)"' "' 
			   6 `" `"Infant"' `"mortality"' `"(/1000)"' "' 
			   10 `" `"Health"' `"subsidies"' `"(% of poor)"' "' 
			   14 `" `"Aqueduct"' `"access"'  `"(%)"' "' 
			   18 `" `"Sewerage"' `"access"' `"(%)"' "' 
			   22 `" `"Water"' `"pollution"' `"(index)"' "', labsize(small)) 
		legend(order(1 "Full sample" 2 "Cadastral update" 3 "Oil royalties") 
			   rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(avgs_05,replace);

graph export "${dpappendix}\B-additional\01-figureB1_a.pdf", as(pdf) 
		name("avgs_05") replace;

** Panel B;

twoway 	(bar estimate id if idstr=="full", barwidth(0.9) fintensity(75)) 
		(bar estimate id if idstr=="cad", barwidth(0.9) fintensity(15)) 
		(bar estimate id if idstr=="oil", barwidth(0.9) fintensity(55)) 
		/*(rcap min95 max95 id,color(black))*/ 
		if target==1, 
		ylabel(,angle(horizontal))  
		ytitle(Share of municipalities) 
		xtitle("") 
		xlabel(2 `" `"Educational"' `"enrolment"' `"(=100)"' "' 
			   6 `" `"Infant"' `"mortality"' `"(<16.5)"' "' 
			   10 `" `"Health"' `"subsidies"' `"(=100)"' "' 
			   14 `" `"Aqueduct"' `"access"'  `"(>91.5)"' "' 
			   18 `" `"Sewerage"' `"access"' `"(>85.5)"' "' 
			   22 `" `"Water"' `"pollution"' `"<5"' "', labsize(small)) 
		legend(order(1 "Full sample" 2 "Cadastral update" 3 "Oil royalties") 
			   rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(Davgs_05,replace);

graph export "${dpappendix}\B-additional\01-figureB1_b.pdf", as(pdf) 
		name("Davgs_05") replace;

#d cr

restore

* Figure B2: ------------------------------------------------------------------- 

use "${dpwork}\ESTIMATIONS.dta", clear

	
preserve
	import excel "${dpraw}\02-expenditure\gasto-detallado-10-11-DNP.xlsx", 		///
			firstrow clear	
			
	tab año

	rename año year

	tempfile detail_expenses
	save `detail_expenses'
restore	


merge 1:1 codmpio year using `detail_expenses'

egen pct_salud=rowtotal(pct_cob_tmi pct_cob_rs pct_cob_segalim)

#d ;

** Panel A;

graph bar (mean) pct_salud 
				 pct_cob_educ 
				 pct_cob_apsb 
				 pct_cob 
				 if year>=2010&year<=2011&valid==1&r_oilpcravg>0&pct_cob!=0, 
		showyvars 
		yvaroptions(relabel(1 "Health" 2 "Education" 3 "Water" 4 "Total")) 
		bargap(20) 
		outergap(*1.2) 
		intensity(50) 
		ytitle("Investment of Natural Resource Royalties (%)") 
		yline(75, lpattern(dash) lcolor(red)) 
		ylabel(, angle(horizontal)) 
		legend(off) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white));

graph export "${dpappendix}\B-additional\02-figureB2_a.pdf", as(pdf) replace;

** Panel B;

histogram pct_cob if year>=2010&year<=2011&valid==1&r_oilpcravg>0&pct_cob!=0, 
		width(5) 
		start(45) 
		fraction 
		barwidth(4.8) 
		ytitle(Share of Municipalities (Oil-producers)) 
		ylabel(, angle(horizontal)) 
		xtitle(Investment of royalties in required sectors (%)) 
		xline(75, lwidth(medium) lpattern(dash) lcolor(red))
		xlabel(50(10)100) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white));

graph export "${dpappendix}\B-additional\02-figureB2_b.pdf", as(pdf) replace;

#d cr

* Figure B4: ------------------------------------------------------------------- 

use "${dpwork}\ESTIMATIONS.dta", clear

preserve
 collapse r_oilpcravg ${if},by(codmpio)
 xtile qroy = r_oilpcravg if r_oilpcravg>0, n(2)
 tab qroy
 replace qroy=0 if qroy==.
 tempfile qroy
 save `qroy'
restore

merge m:1 codmpio using `qroy', keepusing(qroy)

#d ;

** Panel A;
graph bar (mean) y_k_rega_pcr if year>=2005&year<=2011&valid==1, 
		over(year, label(angle(forty_five))) 
		over(qroy, relabel(1 "No oil" 2 "Below median" 3 "Above median")) 
		ytitle(Average Natural Resource Royalties Per Capita) 
		ylabel(0(50)150, angle(horizontal)) 
		name(y_k_rega_p50,replace) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white));

graph export "${dpappendix}\B-additional\04-figureB4_a.pdf", as(pdf) replace;

* Panel B;
graph bar (mean) y_total_pcr if year>=2005&year<=2011&valid==1, 
		over(year, label(angle(forty_five))) 
		over(qroy, relabel(1 "No oil" 2 "Below median" 3 "Above median")) 
		ytitle(Average Total Revenue Per Capita) 
		ylabel(0(50)150, angle(horizontal)) 
		name(y_total_p50,replace) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white));

graph export "${dpappendix}\B-additional\04-figureB4_b.pdf", as(pdf) replace;

#d cr

* Table B1: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

gen lacu_tot=ln(1+acu_tot)
gen lirca07=ln(1+irca07)
gen lalc_tot=ln(1+alc_tot)

#d ;
local out outreg2 using "${dpappendix}\B-additional\05-tableB1", 
	dec(3)  tex(frag) nonot
	keep(lacu_tot lalc_tot) 
	nocons;
#d cr

* Column 1:
reg lirca07 lacu_tot ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, No) replace

* Column 2:
reg lirca07 lacu_tot i.coddepto ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, Yes) 

* Column 3: 
reg lirca07 lalc_tot ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, No)  

* Column 4:
reg lirca07 lalc_tot i.coddepto ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, Yes) 

* Column 5:
reg lirca07 lacu_tot lalc_tot ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, No)  

* Column 6:
reg lirca07 lacu_tot lalc_tot i.coddepto ${if}&year==2005, cluster(coddepto)
`out' addtext(Department FE, Yes) 

* Table B2: --------------------------------------------------------------------
 
use "${dpwork}\ESTIMATIONS.dta", clear

#d ;
gen new_muni85=inlist(codmpio,05390,05652,05659,13030,13042,13062,13160,13188,
							  13222,13268,13300,13458,13490,13580,13620,13655,
							  13810,15236,17495,17665,18785,19290,19300,19533,
							  19780,19785,19845,20570,23300,23350,23682,23815,
							  25260,25312,27050,27135,27150,27160,27250,27425,
							  27430,27450,27580,27600,27810,44035,44090,44098,
							  44110,44378,44420,47030,47205,47268,47460,47545,
							  47660,47720,47960,47980,50110,50270,50325,50370,
							  50450,52240,52254,52385,52390,52480,52565,52685,
							  52694,54250,54385,54553,68235,68250,70221,70233,
							  73520,81300,86569,86571,86757,91430,91530,91536,
							  94663,99773);

gen oil_muni=(r_oilpcravg>0&r_oilpcravg<.);

egen tax_muni=max(post_update0610any),by(codmpio);

foreach x of varlist pop_total indrural nbi acu_tot alc_tot cob_eelectr 
					 y_total_pcr g_total_pcr Dgue Dpar consultas0_pc 
					 low_weight_pc cob01_bcg cob01_dpt cob01_pol tmi 
					 defunciones01_pc eda_ira01_pc {;
					 
	gen temp=`x' if year==2005;
	
	egen `x'_05=max(temp),by(codmpio);
	
	drop temp;
	
};

replace pop_total_05=pop_total_05/1000;

bysort codmpio (year): replace notarias=notarias[_n-1] 
	if codmpio==codmpio[_n-1]&year>2005;
	
egen cons_com0205=sum(cons_com) if year>=2002&year<=2005,by(codmpio);

gen Dcons_com0205=cons_com0205>0 if year>=2002&year<=2005&cons_com0205<.;

foreach x of varlist peagrariac notarias peofdereci {;
	gen D`x'=`x'>0 if `x'<.;
	replace D`x'=0 if D`x'==.; // new munis ;
};

foreach x of varlist indrural_05 consultas0_pc_05 low_weight_pc_05 {;
	replace `x'=`x'*100;
};

** Extract vars from muni-period dataset;
preserve;
	use "${dpwork}\ESTIMATIONS-TERM.dta", clear;
	
	keep if period==1;
	keep codmpio alcalde alcalde_sum alcalde_1 alcalde_2 alcalde_3; 
	tempfile pgn ;
	save `pgn';
restore;

local vars0 area altura pop_total_05 indrural_05 new_muni85 disbogota discapital 
			Dnotarias Dpeagrariac Dpeofdereci Dcons_com0205 Dgue_05 Dpar_05 
			y_total_pcr_05 g_total_pcr_05 nbi_05 acu_tot_05 alc_tot_05 
			cob_eelectr_05 cnbas05 cobrs05 irca07 Dcnbas10005 Dcobrs10005 
			Dirca0507 consultas0_pc_05 low_weight_pc_05 cob01_bcg_05 
			cob01_dpt_05 cob01_pol_05 tmi_05 defunciones01_pc_05 
			eda_ira01_pc_05;

preserve;

	collapse `vars0' oil_muni tax_muni ${if},by(codmpio coddepto);
	
	merge 1:1 codmpio using `pgn';
	
	local vars `vars0' alcalde alcalde_sum alcalde_1 alcalde_2 alcalde_3;
	
	local out outreg2 using "${dpappendix}\B-additional\06-tableB2", dec(2) tex(frag) nonot nocons;
	
	local replace replace;
	
	foreach x of varlist `vars' {;

		reghdfe `x' oil_muni tax_muni, absorb(coddepto) vce(robust) nocons;
		
		test oil=tax;
		
		local p_val: di %4.3fc r(p);
		
		sum `e(depvar)' if e(sample);
		
		if "`x'"=="eda_ira01_pc_05" local replace ;
		
		`out' ctitle(`x') adds(DV mean,r(mean)) 
			addtext(p-value H0:tax=oil,`p_val') 
			`replace';
			local replace;
		
		};
		
restore;

#d cr

* Table B3: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

merge 1:1 codmpio year using "${dpraw}\02-expenditure\investment.DTA"
drop if _merge==2 //San Andres
drop _merge

#d ;
gen sh_20_otros=sh_04_deporte+sh_05_cultura+sh_06_otros_servicios+sh_07_vivienda
			   +sh_08_agricultura+sh_10_ambiente+sh_11_carcel+sh_12_desastres
			   +sh_13_desarrollo+sh_14_vulnerables+sh_15_equipamiento
			   +sh_16_comunidad+sh_17_fortalecimiento+sh_18_justicia;
#d cr

gen sh_social=sh_01_educacion+sh_02_salud+sh_03_agua

foreach x in 01_educacion 02_salud 03_agua 09_transporte 20_otros social{
	gen i_`x'_pcr=i_pcr*sh_`x'
	gen li_`x'_pcr=ln(1+i_`x'_pcr)
}

** Panel A:

local out outreg2 using "${dpappendix}\B-additional\07-tableB3_a", dec(3) tex(frag) nonot nocons

local replace replace

foreach x in social 01_educacion 02_salud 03_agua 09_transporte 20_otros{

	reghdfe li_`x'_pcr $rf_log ${if}, $fe $cluster 

	sum i_`x'_pcr if e(sample)
	
	if "`x'"=="20_otros" local replace 
	
	`out' adds(DV mean,r(mean)) ctitle(`x') `replace'
	
	local replace
}

** Panel B:

local out outreg2 using "${dpappendix}\B-additional\07-tableB3_b", dec(3) tex(frag) nonot nocons nor2

local replace replace

foreach x in social 01_educacion 02_salud 03_agua 09_transporte 20_otros{
	
	ivreghdfe li_`x'_pcr $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	
	if "`x'"=="20_otros" local replace 
	
	`out' ctitle(`x') $add_iv `replace'
	
	local replace
}

* Table B4: --------------------------------------------------------------------
 
use "${dpwork}\ESTIMATIONS.dta", clear

gen post_update0610any_oil=post_update0610any*(r_oilpcravg>0&r_oilpcravg<.)

local out outreg2 using "${dpappendix}\B-additional\08-tableB4", dec(3) tex(frag) nonot nocons

** Column 1:
reghdfe lcnbas $rf_level post_update0610any_oil ${if}, $fe $cluster   
	sum cnbas if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(cnbas) replace	

** Column 2:
reghdfe lcobrs $rf_level post_update0610any_oil ${if}, $fe $cluster 
	sum cobrs if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(cobrs)

** Column 3:
reghdfe lirca $rf_level post_update0610any_oil ${if}, $fe $cluster 
	sum irca if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(irca)

** Column 4:
reghdfe Dcnbas100 $rf_level post_update0610any_oil ${if}, $fe $cluster   
	sum Dcnbas100 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dcnbas) 	

** Column 5:
reghdfe Dcobrs100 $rf_level post_update0610any_oil ${if}, $fe $cluster 
	sum Dcobrs100 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dcobrs) 

** Column 6
reghdfe Dirca05 $rf_level post_update0610any_oil ${if}, $fe $cluster 
	sum Dirca05 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dirca) 

* Table B5: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS-TERM.dta", clear

drop if period==1

collapse (max) alcalde_1,by(codmpio)

tempfile pgn
save `pgn'

use "${dpwork}\ESTIMATIONS.dta", clear

merge m:1 codmpio using `pgn'

gen tax_pgn=post_update0610any*alcalde_1
gen roy_pgn=roy_ipoil*alcalde_1

local out outreg2 using "${dpappendix}\B-additional\09-tableB5", dec(3) tex(frag) nonot nocons

** Panel 1:
reghdfe lcnbas $rf_level tax_pgn roy_pgn ${if}, $fe $cluster   
	sum cnbas if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(cnbas) replace	

** Panel 2:
reghdfe lcobrs $rf_level tax_pgn roy_pgn ${if}, $fe $cluster 
	sum cobrs if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(cobrs)

** Panel 3:
reghdfe lirca $rf_level tax_pgn roy_pgn ${if}, $fe $cluster 
	sum irca if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(irca)

** Panel 4:
reghdfe Dcnbas100 $rf_level tax_pgn roy_pgn ${if}, $fe $cluster   
	sum Dcnbas100 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dcnbas) 	

** Panel 5:
reghdfe Dcobrs100 $rf_level tax_pgn roy_pgn ${if}, $fe $cluster 
	sum Dcobrs100 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dcobrs) 

** Panel 6:
reghdfe Dirca05 $rf_level tax_pgn roy_pgn ${if}, $fe $cluster 
	sum Dirca05 if e(sample)   
	`out' adds(DV mean,r(mean)) ctitle(Dirca) 

*-------------------------------------------------------------------------------*
**# APPENDIX C:
*-------------------------------------------------------------------------------*

* Table C1: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

* Panel A: Local public finance
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_a"

** Column 1:
reghdfe ly_tax_pred_pcr pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist ly_tax_ica_pcr ly_tax_gas_pcr ly_tax_otr_post00_pcr  
					 ly_notax_pcr ly_trf_pcr ly_k_rega_pcr lroy ly_k_trf_pcr
					 ly_k_cofin_pcr lsgp_educacion_pcr lsgp_salud_pcr 
					 lsgp_aguapot_pcr lsgp_propgen_pcr
					 lg_fct_pcr lg_int_debt_pcr li_fbkf_pcr li_otr_pcr
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};

#d cr

* Panel B: Local public goods
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_b"

** Column 1:
reghdfe lcnbas pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist lcobrs lirca ltmi ldefunciones01_pc leda_ira01_pc 
					 lconsultas0_pc llow_weight_pc
					 lcob01_bcg lcob01_dpt lcob01_pol
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};

#d cr

* Panel C: Chime and conflict
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_c"

** Column 1:
reghdfe lmurders_pc pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist Dgue lgue_pc Dpar lpar_pc D_Coca
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr

* Panel D: National government policies
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_d"

** Column 1:
reghdfe Dcons_com pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist lba_tot_vr_pcr lfaccion
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr

* Panel E: Last mayoral election
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_e"

** Column 1:
reghdfe myr_no_election_eff pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist myr_ncandidates_myr_eff myr_sh_null_r1_eff 
					 myr_sh_empty_r1_eff myr_sh_winner_v_eff myr_margin_eff
					 myr_sh_inc_eff myr_reelect_eff myr_hhi_norm_eff
					 myr_left_eff myr_left_rwc_eff 
					 myr_para_eff myr_lib_eff myr_cons_eff myr_new_parties_eff
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr

* Panel F: Last council elections
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_f"

** Column 1:
reghdfe no_cons pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist parties_seat hhi_cons_norm pct_myr_cons cons_sh_left 
					 cons_sh_para cons_sh_new cons_sh_lib 
					 cons_sh_cons
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr

* Panel G: Last gubernatorial elections
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_g"

** Column 1:
reghdfe sh_winner_gob pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist gob_myr
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr


* Panel H: Last presidential election
local out outreg2 using "${dpappendix}\C-cadastral-tests\01-tableC1_h"

** Column 1:
reghdfe pres_sh_null_r1_eff pre_trend post_update0610any ${if}, $fe $cluster 	
test pre_trend
local temp: di %4.3fc r(p)
`out',  addtext(p-value pre_trend,"`temp'") replace tex(frag) nonot drop(post_update0610any) nocons dec(3) nor2

#d ;
foreach x of varlist pres_sh_empty_r1_eff pres_sh_vblank_r1_eff
					 pres_sh_winner_r1_eff pres_sh_left_r1_eff 
					 pres_sh_lib_r1_eff pres_sh_cons_r1_eff
					 pres_sh_uri_r1_eff pres_sh_inc_r1_eff
					 {;

	reghdfe `x' pre_trend post_update0610any ${if}, $fe $cluster;
		test pre_trend;
		local temp: di %4.3fc r(p);
		`out', ctitle(`x') addtext(p-value pre_trend,"`temp'")  tex(frag) nonot
				nocons drop(post_update0610any)  dec(3) nor2;
};


#d cr

* Figure C1: ------------------------------------------------------------------- 


** Panel A:
use "${dpwork}\ESTIMATIONS.dta", clear

cap egen ageatu_min=rowmin(ageatu ageatu_r)

foreach x of numlist 2/11{
	cap gen age_`x'=(ageatu_min==`x')
}
cap gen age_12p=(ageatu_min>11)

reghdfe N1any age_2-age_5 age_7-age_12p ${if}, $fe $cluster

parmest, saving("${dptemp}\prob_up.dta",replace)

#d ;
preserve;
 use "${dptemp}\prob_up.dta",clear;
 
 gen age=_n+1;
 replace age=age+1 in 5/10;
 
 set obs 11;
 
 replace age = 6 in 11;
 replace max95 = 0 in 11;
 replace min95 = 0 in 11;
 replace estimate = 0 in 11;
 
 sort age ;
 
 lab define age 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "10" 	
				12 "11+" 13 "12" 14 "13" 15 "14" 16 "15" 17 "16+";

 label values age age;
 
 twoway (scatter estimate age) 
		(rcap min95 max95 age), 
		ylabel(, angle(horizontal)) 
		xlabel(2(1)12, valuelabel) 
		legend(off) 
		ytitle(Probability of cadastral update) 
		xtitle(Years since last update) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(prob_up,replace);

 graph export "${dpappendix}\C-cadastral-tests\02-figureC1_a.pdf", as(pdf) 
		name(prob_up) replace;

restore;

#d cr

** Panel B:

use "${dpwork}\ESTIMATIONS.dta", clear

preserve
keep if (year>2000&year<=2011&N1any==1)|year==2000
gen dt=year-year[_n-1] if codmpio==codmpio[_n-1]
gen g=((vt_ppr/vt_ppr[_n-1])^(1/dt))-1 if  codmpio==codmpio[_n-1]

foreach x of numlist 1/11{
gen dt_`x'=(dt==`x')
} 

reg g dt_1 dt_2 dt_3 dt_4 dt_6 dt_7 dt_8 dt_9 dt_10 dt_11 i.coddepto#i.year 	///
		$if &N1any==1, cluster(dpt_year)
	test dt_3=dt_4=dt_6=dt_7=dt_8=dt_9=dt_10
	global temp: di %4.3fc r(p)
	parmest, saving("${dptemp}\propval.dta",replace)

use "${dptemp}\propval.dta",clear

keep in 1/10

gen id=[_n]
replace id=id+1 in 5/10

set obs 11

replace id = 5 in 11
replace max95 = 0 in 11
replace min95 = 0 in 11
replace estimate = 0 in 11

sort id

#d ;
lab define id 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10" 	///
			  11 "11+";
label values id id ;

twoway 	(scatter estimate id) 
		(rcap min95 max95 id), 
		ylabel(, angle(horizontal)) 
		xlabel(1(1)11, valuelabel) 
		legend(off) 
		ytitle("Property values (yearly growth rate)") 
		xtitle(Years since last update) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		caption("p-value (H0: Coefficients yrs 3-10 equal)=${temp}" " ",
				pos(5) ring(0)) 
		name(propval,replace);

graph export "${dpappendix}\C-cadastral-tests\02-figureC1_b.pdf", as(pdf) 
		name(propval) replace;

#d cr

restore

* Figure C2: ------------------------------------------------------------------- 

use "${dpwork}\ESTIMATIONS.dta", clear

**share w/ update 04-11
gen temp=(cu_fix>=2004&cu_fix<=2011)|(cr_fix>=2004&cr_fix<=2011)
egen update0411=max(temp),by(codmpio)
tab update0411 if year==2005

cap gen munis=1

cap gen N1uu=(N1u==1&N1r==0)
cap gen N1rr=(N1r==1&N1u==0)

#d;

** Panel A;

preserve;
 collapse (sum) munis N1any N1uu N1rr N1both if igac==1&corregimiento==0, 
		by(year president) ;
 label define prescond 1 "Pastrana               (no target)" 
					   2 "Uribe 1                (100% urban)" 
					   3 "Uribe 2                (90% urban, 70% rural)", modify;

 label values president prescond;

 splitvallabels president, length(22) recode;
 
 graph bar (asis) N1uu N1rr N1both if year>=2000&year<=2011, 
		over(year, label(angle(forty_five))) 
		over(president, relabel(`r(relabel)') ) 
		nofill 
		stack 
		bar(1, fcolor(green) lcolor(green) fintensity(75)) 
		bar(2, fcolor(eltblue) lcolor(eltblue) fintensity(15)) 
		bar(3, fcolor(stone) lcolor(stone) fintensity(65)) 
		ytitle(Number of municipalities) 
		ylabel(, angle(horizontal)) 
		legend(order(1 "only urban" 2 "only rural" 3 "urban and rural") rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))  
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(ups_type,replace);

 graph export "${dpappendix}\C-cadastral-tests\03-figureC2_a.pdf", as(pdf)		///
		name(ups_type) replace;
		
restore;

#d cr

** Panel B;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ;

reghdfe ly_tax_pred_pcr post2002w-post2011w if year>=2000  &year<=2012 &
		igac==1 & y_tax_pred!=0, $fe $cluster;

	test post2002w=post2003w=post2004w=post2005w=post2006w=post2007w=post2008w
			=post2009w=post2010w=post2011w;
	global temp: di %4.3fc r(p);

parmest, saving("${dptemp}\pred_returns_w.dta",replace);

preserve;
 use "${dptemp}\pred_returns_w.dta", clear;
 gen year=_n+2001;
 twoway (scatter estimate year) 
		(rcap min95 max95 year) in 1/10, 
		ylabel(, angle(horizontal)) 
		xlabel(2002(1)2011,angle(45)) 
		ylabel(-0.2(0.1)0.4) 
		legend(off) 
		ytitle(Effect of cadastral update on log property tax revenue) 
		xtitle(Update cohort) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		caption("p-value (H0: All coefficients equal)=${temp}" " ", 
				 pos(5) ring(0)) name(post_yr_w,replace);
				 
 graph export "${dpappendix}\C-cadastral-tests\03-figureC2_b.pdf", as(pdf) 
		name(post_yr_w) replace;
restore;

#d cr


*-------------------------------------------------------------------------------*
**# APPENDIX D:
*-------------------------------------------------------------------------------*

* Figure D1: ------------------------------------------------------------------- 

** Panel A:
use "${dpwork}\ESTIMATIONS.dta", clear

#d ;

reghdfe ly_k_rega_pcr Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 
		Droy_2011 ${if}, $fe $cluster;

parmest,saving("${dptemp}\event_ly_k_rega_pcr", replace);

use "${dptemp}\event_ly_k_rega_pcr", clear;

drop in 7;
set obs 7;

gen year=substr(parm,6,4);
destring year,replace;
replace year=2005 if year==.;
sort year;

gen ind_price_oil_cop_r=1.190233;
replace ind_price=1.394467 if year==2006;
replace ind_price=1.285121 if year==2007;
replace ind_price=1.542736 if year==2008;
replace ind_price=1.054039 if year==2009;
replace ind_price=1.152482 if year==2010;
replace ind_price=1.422329 if year==2011;

mvencode estimate min95 max95,mv(0);

twoway 	(scatter estimate year) 
		(rcap min95 max95 year) 
		(connect ind_price_oil_cop_r year, msymbol(X) msize(large) yaxis(2)) , 
		ytitle("Log Royalties per capita") 
		ylabel(, angle(horizontal)) 
		ytitle(Oil price index (2004=1), axis(2)) 
		ylabel(, angle(horizontal) axis(2)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI" 3 "Oil Price") rows(1))  
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(ly_k_rega_pcr0511,replace);
		
graph export "${dpappendix}\D-robustness\01-figureD1_a.pdf", as(pdf) replace;

#d cr 

** Panel B;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ;

reghdfe ly_total_pcr Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 Droy_2011
		${if}, $fe $cluster;

parmest,saving("${dptemp}\event_ly_total_pcr", replace);

use "${dptemp}\event_ly_total_pcr", clear;

drop in 7;
set obs 7;

gen year=substr(parm,6,4);
destring year,replace;

replace year=2005 if year==.;

sort year;

mvencode estimate min95 max95,mv(0);

twoway  (scatter estimate year) 
		(rcap min95 max95 year), 
		ytitle("Log Total Revenue per capita")
		ylabel(, angle(horizontal)) xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1))
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
		name(ly_total_pcr0511,replace);
		
graph export "${dpappendix}\D-robustness\01-figureD1_b.pdf", as(pdf) replace;

#d cr 

** Panel C;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ;

reghdfe lg_total_pcr Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 Droy_2011
		${if}, $fe $cluster;
		
parmest,saving("${dptemp}\event_lg_total_pcr", replace);

use "${dptemp}\event_lg_total_pcr", clear;

drop in 7;
set obs 7;

gen year=substr(parm,6,4);
destring year,replace;
replace year=2005 if year==.;

sort year;

mvencode estimate min95 max95,mv(0);

twoway 	(scatter estimate year) 
		(rcap min95 max95 year), 
		ytitle("Total Spending per capita") 
		ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(lg_total_pcr0511,replace);
		
graph export "${dpappendix}\D-robustness\01-figureD1_c.pdf", as(pdf) replace;

#d cr 

** Panel D;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ;  

reghdfe lcnbas Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 Droy_2011 
		${if}, $fe $cluster;

parmest,saving("${dptemp}\event_lcnbas", replace);

preserve;
 use "${dptemp}\event_lcnbas", clear;
 
 drop in 7;
 set obs 7;
 
 gen year=substr(parm,6,4);
 destring year,replace;
 replace year=2005 if year==.;
 
 sort year;
 
 mvencode estimate min95 max95,mv(0);
 
 twoway (scatter estimate year) 
		(rcap min95 max95 year), 
		ytitle("ln Educational enrolment rate") 
		ylabel(, angle(horizontal))
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1))  
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_cnbas0511,replace);

 graph export "${dpappendix}\D-robustness\01-figureD1_d.pdf", as(pdf)
		name("oil_cnbas0511") replace;


restore;

#d cr 		

** Panel E;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ;

reghdfe lcobrs Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 Droy_2011 
		${if}, $fe $cluster;

parmest,saving("${dptemp}\event_lcobrs", replace);

preserve;

 use "${dptemp}\event_lcobrs", clear;

 drop in 7;
 set obs 7;
 
 gen year=substr(parm,6,4);
 destring year,replace;
 replace year=2005 if year==.;
 
 sort year;
 
 mvencode estimate min95 max95,mv(0);
 
 twoway (scatter estimate year) 
		(rcap min95 max95 year) , 
		ytitle("ln Percentage of poor w/ subsidized health") 
		ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1))  ///
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_cobrs0511,replace);

 graph export "${dpappendix}\D-robustness\01-figureD1_e.pdf", as(pdf) replace;

restore;

#d cr 

** Panel F;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ; 

reghdfe lirca Droy_2008 Droy_2009 Droy_2010 Droy_2011 ${if}, $fe $cluster;

parmest,saving("${dptemp}\event_lirca", replace);

preserve;

 use "${dptemp}\event_lirca", clear;
 
 drop in 5;
 set obs 5;
 
 gen year=substr(parm,6,4);
 destring year,replace;
 replace year=2007 if year==.;
 
 sort year;
 
 mvencode estimate min95 max95,mv(0);
 
 twoway (scatter estimate year) 
		(rcap min95 max95 year) , 
		ytitle("ln Water pollution index") 
		ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1))  ///
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_irca0511,replace);

 graph export "${dpappendix}\D-robustness\01-figureD1_f.pdf", as(pdf) replace;
		
restore;

#d cr 

** Panel: G;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ; 

reghdfe ltmi Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 Droy_2011 ${if},
		$fe $cluster ;

parmest,saving("${dptemp}\event_ltmi", replace);

preserve;
 use "${dptemp}\event_ltmi", clear;
 
 drop in 7;
 set obs 7;
 
 gen year=substr(parm,6,4);
 destring year,replace;
 
 replace year=2005 if year==.;
 sort year;
 
 mvencode estimate min95 max95, mv(0);
 
 twoway (scatter estimate year) 
		(rcap min95 max95 year) , 
		ytitle("ln Infant mortality rate") 
		ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_tmi0511,replace);

 graph export "${dpappendix}\D-robustness\01-figureD1_g.pdf", as(pdf) replace;
		
restore;

#d cr 

** Panel H;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ; 

reghdfe ldefunciones01_pc Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 
	Droy_2011 ${if}, $fe $cluster;

parmest,saving("${dptemp}\event_ltmi_own", replace);

preserve;

 use "${dptemp}\event_ltmi_own", clear;
 
 drop in 7;
 set obs 7;
 
 gen year=substr(parm,6,4);
 destring year,replace;
 
 replace year=2005 if year==.;
 sort year;
 
 mvencode estimate min95 max95,mv(0);
 
 twoway (scatter estimate year) 
 		(rcap min95 max95 year) , 
		ytitle("ln Infant mortality rate") ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) legend(order(1 "Point estimate" 2 "95% CI") rows(1))
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_tmi_own0511,replace);
 
 graph export "${dpappendix}\D-robustness\01-figureD1_h.pdf", as(pdf) replace;
 
restore;

#d cr

** Panel I;

use "${dpwork}\ESTIMATIONS.dta", clear

#d ; 

reghdfe leda_ira01_pc Droy_2006 Droy_2007 Droy_2008 Droy_2009 Droy_2010 
		Droy_2011 ${if}, $fe $cluster;

parmest,saving("${dptemp}\event_leda_ira", replace);

preserve;

 use "${dptemp}\event_leda_ira", clear;
 
 drop in 7;
 set obs 7;
 
 gen year=substr(parm,6,4);
 destring year, replace;
 
 replace year=2005 if year==.;
 
 sort year;
 
 mvencode estimate min95 max95,mv(0);
 
 twoway (scatter estimate year) 
		(rcap min95 max95 year) , 
		ytitle("ln Infant mortality rate (AD/URI)")
		ylabel(, angle(horizontal)) 
		xlabel(2005(1)2011) 
		legend(order(1 "Point estimate" 2 "95% CI") rows(1)) 
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
		name(oil_tmi_own0511,replace);
		
 graph export "${dpappendix}\D-robustness\01-figureD1_i.pdf", as(pdf)replace;
restore;

#d cr


* Table D1: --------------------------------------------------------------------

** Panel A: IHS ---------------------------------------------------------------- 

use "${dpwork}\ESTIMATIONS.dta", clear

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_a", dec(3) tex(frag) nonot nocons nor2 noobs

*** Column 1:
ivreghdfe ly_total_pcr (ly_tax_pred_pcr = post_update0610any) ${if},$fe $cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax') replace

*** Column 2:
ivreghdfe ly_total_pcr (ly_k_rega_pcr = lroy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 3:
ivreghdfe ly_total_pcr $iv_log ${if},$fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' $add_iv

*** Column 4:
ivreghdfe lg_total_pcr (ly_tax_pred_pcr = post_update0610any) ${if},$fe $cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')
	ivreghdfe lg_total_pcr (ly_k_rega_pcr = lroy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 5:
ivreghdfe lg_total_pcr $iv_log ${if},$fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' $add_iv

*** Column 6:
ivreghdfe li_pcr (ly_tax_pred_pcr = post_update0610any) ${if},$fe $cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')
	ivreghdfe li_pcr (ly_k_rega_pcr = lroy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 7:
ivreghdfe li_pcr $iv_log ${if},$fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' $add_iv 


** Panel B: IHS ----------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

gen ihs_y_tax_pred_pcr=asinh(y_tax_pred_pcr)
gen ihs_y_k_rega_pcr=asinh(y_k_rega_pcr)
gen ihs_roy=asinh(roy)

gen ihs_y_total_pcr=asinh(y_total_pcr)
gen ihs_g_total_pcr=asinh(g_total_pcr)
gen ihs_i_pcr=asinh(i_pcr)

global rf_ihs post_update0610any ihs_roy
global iv_ihs (ihs_y_tax_pred_pcr ihs_y_k_rega_pcr = post_update0610any ihs_roy)
global test_ihs test ihs_y_tax_pred_pcr = ihs_y_k_rega_pcr

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_b", dec(3) tex(frag) nonot nocons nor2 noobs 

*** Column 1:
ivreghdfe ihs_y_total_pcr (ihs_y_tax_pred_pcr = post_update0610any) ${if}, 		///
		$fe $cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax') replace

*** Column 2:
ivreghdfe ihs_y_total_pcr (ihs_y_k_rega_pcr = ihs_roy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 3:
ivreghdfe ihs_y_total_pcr $iv_ihs ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_ihs
	$p_val
	`out' $add_iv

*** Column 4:
ivreghdfe ihs_g_total_pcr (ihs_y_tax_pred_pcr = post_update0610any) ${if},$fe 	///
		$cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')

*** Column 5:
ivreghdfe ihs_g_total_pcr (ihs_y_k_rega_pcr = ihs_roy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 6:
ivreghdfe ihs_g_total_pcr $iv_ihs ${if},$fe $cluster ffirst
	$F_tax
	$F_roy
	$test_ihs
	$p_val
	`out' $add_iv
	
*** Column 7:
ivreghdfe ihs_i_pcr (ihs_y_tax_pred_pcr = post_update0610any) ${if},$fe $cluster
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')

*** Column 8:
ivreghdfe ihs_i_pcr (ihs_y_k_rega_pcr = ihs_roy) ${if},$fe $cluster
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 9:
ivreghdfe ihs_i_pcr $iv_ihs ${if},$fe $cluster ffirst
	$F_tax
	$F_roy
	$test_ihs
	$p_val
	`out' $add_iv 

** Panel C: Level --------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

local out outreg2 using  "${dpappendix}\D-robustness\02-tableD1_c", dec(3) tex(frag) nonot nocons nor2 noobs 

*** Column 1:
ivreghdfe y_total_pcr (y_tax_pred_pcr = post_update0610any) ${if}, $fe $cluster ///
		ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax') replace
	ivreghdfe y_total_pcr (y_k_rega_pcr = roy_ipoil) ${if}, $fe $cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy')
 
*** Column 2:
ivreghdfe y_total_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any 		///
		roy_ipoil) ${if}, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv

*** Column 3:
ivreghdfe g_total_pcr (y_tax_pred_pcr = post_update0610any) ${if}, $fe $cluster ///
		ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')
	ivreghdfe g_total_pcr (y_k_rega_pcr = roy_ipoil) ${if}, $fe $cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 4:
ivreghdfe g_total_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any 		///
		roy_ipoil) ${if}, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv

*** Column 5:
ivreghdfe i_pcr (y_tax_pred_pcr = post_update0610any) ${if}, $fe $cluster ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')

*** Column 6:
ivreghdfe i_pcr (y_k_rega_pcr = roy_ipoil) ${if}, $fe $cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 7:
ivreghdfe i_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any roy_ipoil) 	///
		${if}, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv 
	
** Panel D: Level w/ quadratic -------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

gen roy_ipoil2=roy_ipoil^2
gen y_k_rega_pcr2=y_k_rega_pcr^2

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_d", dec(3) tex(frag) nonot nocons nor2 noobs 

#d ;
global F_roy2 local F_roy2: di %4.2fc e(first)[8,3];
global add_iv2 addtext(F-stat tax, \`F_tax', F-stat royalties,  \`F_roy', F-stat royalties 2,  \`F_roy2', p-value H0:tax=royalties,"\`p_val'");
#d cr

*** Columns 1-3: 
ivreghdfe y_total_pcr (y_k_rega_pcr = roy_ipoil) ${if}, $fe $cluster ffirst
	`out' drop(y_k_rega_pcr) replace 
	`out' drop(y_k_rega_pcr)
	`out' drop(y_k_rega_pcr)

*** Columns 4-5: 
ivreghdfe g_total_pcr (y_k_rega_pcr y_k_rega_pcr2 = roy_ipoil roy_ipoil2) 		///
		${if}, $fe $cluster ffirst
	$F_tax //fake, but it's in the right position to capture y_k_rega
	$F_roy
	`out' drop(y_k_rega_pcr*) 
	`out' addtext(F-stat royalties, `F_tax', F-stat royalties 2, `F_roy')

*** Column 6: 
ivreghdfe g_total_pcr (y_tax_pred_pcr y_k_rega_pcr y_k_rega_pcr2 = 				///
		post_update0610any roy_ipoil roy_ipoil2) ${if}, $fe $cluster ffirst
	$F_tax 
	$F_roy
	$F_roy2
	sum y_k_rega_pcr if e(sample)&roy_ipoil>0
	local roy_avg: di %4.2fc r(mean)
	test y_tax_pred_pcr=y_k_rega_pcr+(2*`roy_avg'*y_k_rega_pcr2)
	$p_val
	`out' $add_iv2

*** Columns 7-8: 
ivreghdfe i_pcr (y_k_rega_pcr y_k_rega_pcr2 = roy_ipoil roy_ipoil2) ${if}, $fe 	///
		$cluster ffirst
	$F_tax //fake, but it's in the right position to capture y_k_rega
	$F_roy
	`out' drop(y_k_rega_pcr*) 
	`out' addtext(F-stat royalties, `F_tax', F-stat royalties 2, `F_roy')

*** Column 9: 
ivreghdfe i_pcr (y_tax_pred_pcr y_k_rega_pcr y_k_rega_pcr2 = post_update0610any ///
		roy_ipoil roy_ipoil2) ${if}, $fe $cluster ffirst
	$F_tax 
	$F_roy
	$F_roy2
	sum y_k_rega_pcr if e(sample)&roy_ipoil>0
	local roy_avg: di %4.2fc r(mean)
	test y_tax_pred_pcr=y_k_rega_pcr+(2*`roy_avg'*y_k_rega_pcr2)
	$p_val
	`out' $add_iv2 

** Panel E: w/o Castilla la Nueva ----------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_e", dec(3) tex(frag) nonot nocons nor2  

*** Column 1: 
ivreghdfe y_total_pcr (y_tax_pred_pcr = post_update0610any) ${if} 				///
		& codmpio!=50150, $fe $cluster ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax') replace

*** Column 2: 
ivreghdfe y_total_pcr (y_k_rega_pcr = roy_ipoil) ${if} & codmpio!=50150, $fe 	///
		$cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 3: 
ivreghdfe y_total_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any 		///
		roy_ipoil) ${if} & codmpio!=50150, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv

*** Column 4: 
ivreghdfe g_total_pcr (y_tax_pred_pcr = post_update0610any) ${if} & 			///
		codmpio!=50150, $fe $cluster ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')

*** Column 5: 
ivreghdfe g_total_pcr (y_k_rega_pcr = roy_ipoil) ${if} & codmpio!=50150, $fe 	///
		$cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 6: 
ivreghdfe g_total_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any 		///
		roy_ipoil) ${if} & codmpio!=50150, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv

*** Column 7: 
ivreghdfe i_pcr (y_tax_pred_pcr = post_update0610any) ${if} & codmpio!=50150, 	///
		$fe $cluster ffirst  
	local F_tax: di %4.2fc e(widstat)
	`out' addtext(F-stat tax, `F_tax')

*** Column 8: 
ivreghdfe i_pcr (y_k_rega_pcr = roy_ipoil) ${if} & codmpio!=50150, $fe $cluster ///
	ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' addtext(F-stat royalties, `F_roy') 

*** Column 9: 
ivreghdfe i_pcr (y_tax_pred_pcr y_k_rega_pcr = post_update0610any roy_ipoil) 	///
	${if} & codmpio!=50150, $fe $cluster ffirst 
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' $add_iv 

** Panel F:level w/ lag --------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

gen roy_ipoil_l1=roy_ipoil[_n-1] if codmpio==codmpio[_n-1] & year==year[_n-1]+1
gen y_k_rega_pcr_l1=y_k_rega_pcr[_n-1] if codmpio==codmpio[_n-1] & 				///
		year==year[_n-1]+1

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_f", dec(3) tex(frag) nonot nocons nor2 noobs 


*** Columns 1-3: 
ivreghdfe y_total_pcr (y_k_rega_pcr_l1 = roy_ipoil_l1) ${if}, $fe $cluster 		///
		ffirst
	`out' drop(y_k_rega_pcr_l1) replace 
	`out' drop(y_k_rega_pcr_l1)
	`out' drop(y_k_rega_pcr_l1)

*** Columns 4-5: 
ivreghdfe g_total_pcr (y_k_rega_pcr_l1 = roy_ipoil_l1) ${if}, $fe $cluster 		///
		ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' drop(y_k_rega_pcr_l1)
	`out' addtext(F-stat royalties, `F_roy')

*** Column 6: 
ivreghdfe g_total_pcr (y_tax_pred_pcr y_k_rega_pcr_l1 = post_update0610any 		///
		roy_ipoil_l1) ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	test y_tax_pred_pcr=y_k_rega_pcr_l1
	$p_val
	`out' $add_iv

*** Columns 7-8: 
ivreghdfe i_pcr (y_k_rega_pcr_l1 = roy_ipoil_l1) ${if}, $fe $cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' drop(y_k_rega_pcr_l1)
	`out' addtext(F-stat royalties, `F_roy')

*** Column 9: 
ivreghdfe i_pcr (y_tax_pred_pcr y_k_rega_pcr_l1 = post_update0610any 			///
		roy_ipoil_l1) ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	test y_tax_pred_pcr=y_k_rega_pcr_l1
	$p_val
	`out' $add_iv 

** Panel G: level w/ cumul -----------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

bysort codmpio (year): gen y_k_rega_pcr_cum=sum(y_k_rega_pcr) if year>=2005 & 	///
		year<=2011
bysort codmpio (year): gen roy_ipoil_cum=sum(roy_ipoil) if year>=2005 & 		///
		year<=2011
bysort codmpio (year): gen y_total_pcr_cum=sum(y_total_pcr) if year>=2005 &		///
		year<=2011
bysort codmpio (year): gen g_total_pcr_cum=sum(g_total_pcr) if year>=2005 & 	///
		year<=2011
bysort codmpio (year): gen i_pcr_cum=sum(i_pcr) if year>=2005&year<=2011

local out outreg2 using "${dpappendix}\D-robustness\02-tableD1_g", dec(3) tex(frag) nonot nocons nor2 noobs 


*** Columns 1-3: 
ivreghdfe y_total_pcr_cum (y_k_rega_pcr_cum = roy_ipoil_cum) ${if}, $fe 		///
		$cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' drop(y_k_rega_pcr_cum) replace 
	`out' addtext(F-stat royalties, `F_roy')
	`out' drop(y_k_rega_pcr_cum) 

*** Columns 4-6: 
ivreghdfe g_total_pcr_cum (y_k_rega_pcr_cum = roy_ipoil_cum) ${if}, $fe 		///
		$cluster ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' drop(y_k_rega_pcr_cum)  
	`out' addtext(F-stat royalties, `F_roy')
	`out' drop(y_k_rega_pcr_cum) 

*** Columns 7-9:
ivreghdfe i_pcr_cum (y_k_rega_pcr_cum = roy_ipoil_cum) ${if}, $fe $cluster 		///
		ffirst
	local F_roy: di %4.2fc e(widstat)
	`out' drop(y_k_rega_pcr_cum) 
	`out' addtext(F-stat royalties, `F_roy')
	`out' drop(y_k_rega_pcr_cum)  

* Table D2: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

gen roy_ipoil_l1=roy_ipoil[_n-1] if codmpio==codmpio[_n-1] & year==year[_n-1]+1
gen y_k_rega_pcr_l1=y_k_rega_pcr[_n-1] if codmpio==codmpio[_n-1] & 				///
		year==year[_n-1]+1

#d ;
global rf_level_lag post_update0610any roy_ipoil_l1;
global iv_level_lag (y_tax_pred_pcr y_k_rega_pcr_l1 = post_update0610any 
		roy_ipoil_l1);
#d cr

local out outreg2 using "${dpappendix}\D-robustness\03-tableD2", dec(3) tex(frag) nonot nocons nor2 

dis "$iv_level_lag"

** Column 1:
ivreghdfe lcnbas $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cnbas) $add_iv replace 

** Column 2:
ivreghdfe lcobrs $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cobrs) $add_iv

** Column 3:
ivreghdfe lirca $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(lirca) $add_iv

** Column 4:
ivreghdfe Dcnbas100 $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcnbas) $add_iv 

** Column 5:
ivreghdfe Dcobrs100 $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcobrs) $add_iv 

** Column 6:
ivreghdfe Dirca05 $iv_level_lag ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dirca) $add_iv 

* Table D3: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

bysort codmpio (year): gen y_k_rega_pcr_cum=sum(y_k_rega_pcr) if year>=2005 & 	///
		year<=2011
bysort codmpio (year): gen roy_ipoil_cum=sum(roy_ipoil) if year>=2005&year<=2011

*reghdfe y_k_rega_pcr_cum post_update0610any roy_ipoil_cum ${if}, $fe $cluster

global rf_level_cum post_update0610any roy_ipoil_cum
global iv_level_cum (y_tax_pred_pcr y_k_rega_pcr_cum = post_update0610any		///
	roy_ipoil_cum)

local out outreg2 using "${dpappendix}\D-robustness\04-tableD3", dec(3) tex(frag) nonot  nocons nor2

** Column 1:
ivreghdfe lcnbas $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cnbas) $add_iv replace 

** Column 2:
ivreghdfe lcobrs $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cobrs) $add_iv

** Column 3:
ivreghdfe lirca $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(lirca) $add_iv

** Column 4:
ivreghdfe Dcnbas100 $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcnbas) $add_iv 

** Column 5:
ivreghdfe Dcobrs100 $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcobrs) $add_iv 

** Column 6:
ivreghdfe Dirca05 $iv_level_cum ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dirca) $add_iv 

* Table D4: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear


local out outreg2 using "${dpappendix}\D-robustness\05-tableD4", dec(3)  tex(frag) nonot  nocons nor2

** Column 1:
ivreghdfe lcnbas $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(cnbas) $add_iv replace 

** Column 2:
ivreghdfe lcobrs $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(cobrs) $add_iv

** Column 3:
ivreghdfe lirca $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(lirca) $add_iv

** Column 4:
ivreghdfe Dcnbas100 $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(Dcnbas) $add_iv 

** Column 5:
ivreghdfe Dcobrs100 $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(Dcobrs) $add_iv 

** Column 6:
ivreghdfe Dirca05 $iv_log ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(Dirca) $add_iv 

* Table D5: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS-TERM.dta", clear

gen ipoil= price_oil_cop_r/75.062576
gen r_oilpcr00_ipoil= r_oilpcr00* ipoil

local out outreg2 using "${dpappendix}\D-robustness\06-tableD5", dec(3) tex(frag) nonot  nocons nor2

** Column 1:
ivreghdfe alcalde (y_tax_pred_pcr y_k_rega_pcr = post_sum r_oilpcr00_ipoil) 	///
		${if_period}, $fe_period $cluster_period ffirst 	
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(D_mayor) $add_iv replace

** Column 2:
ivreghdfe alcalde_sum (y_tax_pred_pcr y_k_rega_pcr = post_sum r_oilpcr00_ipoil) ///
		${if_period}, $fe_period $cluster_period ffirst	
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(sum_mayor) $add_iv  

** Column 3:
ivreghdfe alcalde_1 (y_tax_pred_pcr y_k_rega_pcr = post_sum r_oilpcr00_ipoil) 	///
		${if_period}, $fe_period $cluster_period ffirst 	
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(D_mayor_spend) $add_iv  

** Column 4:
ivreghdfe alcalde_2 (y_tax_pred_pcr y_k_rega_pcr = post_sum r_oilpcr00_ipoil) 	///
		${if_period}, $fe_period $cluster_period ffirst 	
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(D_mayor_pol) $add_iv  

** Column 5:
ivreghdfe alcalde_3 (y_tax_pred_pcr y_k_rega_pcr = post_sum r_oilpcr00_ipoil) 	///
		${if_period}, $fe_period $cluster_period ffirst 	
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(D_mayor_other) $add_iv    

* Table D6: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

preserve
 collapse r_oilpcravg ${if},by(codmpio)
 xtile qroy = r_oilpcravg if r_oilpcravg>0, n(2)
 tab qroy
 replace qroy=0 if qroy==.
 tempfile qroy
 save `qroy'
restore

merge m:1 codmpio using `qroy',keepusing(qroy)

gen roy_ipoil_p50=roy_ipoil*(qroy==2)

#d ;
global rf_level_p50 post_update0610any roy_ipoil_p50;
global iv_level_p50 (y_tax_pred_pcr y_k_rega_pcr = 
					 post_update0610any roy_ipoil_p50);
#d cr


local out outreg2 using "${dpappendix}\D-robustness\07-tableD6", dec(3) tex(frag) nonot  nocons nor2

** Column 1:
ivreghdfe lcnbas $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(cnbas) $add_iv replace 

** Column 2:
ivreghdfe lcobrs $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(cobrs) $add_iv

** Column 3:
ivreghdfe lirca $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(lirca) $add_iv

** Column 4:
ivreghdfe Dcnbas100 $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(Dcnbas) $add_iv 

** Column 5:
ivreghdfe Dcobrs100 $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(Dcobrs) $add_iv 

** Column 6:
ivreghdfe Dirca05 $iv_level_p50 ${if}, $fe $cluster ffirst
$F_tax
$F_roy
$test_level
$p_val
`out' ctitle(Dirca) $add_iv 

* Table D7: --------------------------------------------------------------------

use "${dpraw}\06-urosario-conflict\collapse-database_URosario_1996-2014.dta",clear 

keep if year>=2000&year<=2011

rename municipality codmpio
gen clash=clnoat+complexd
drop complexd clnoat

merge 1:1 codmpio year using  "${dpwork}\ESTIMATIONS.dta"
mvencode clash atnocl ktotal kciv sec evento gued pard if year>=2000 &	///
		year<=2011,mv(0) over

sort codmpio year

gen Dgue_alt=(gued>0) if gued!=.&year>=2005&year<=2011
gen Dpar_alt=(pard>0) if pard!=.&year>=2005&year<=2011
gen Devento=(evento>0) if evento!=.&year>=2005&year<=2011
gen Dclash=(clash>0) if clash!=.&year>=2005&year<=2011
gen Dattack=(atnocl>0) if atnocl!=.&year>=2005&year<=2011
gen Dsec=(sec>0) if sec!=.&year>=2005&year<=2011
gen evento_pc=evento*10000/pop_total
gen ktotal_pc=ktotal*10000/pop_total

local out outreg2 using "${dpappendix}\D-robustness\08-tableD7", dec(3) tex(frag) nonot nocons nor2

local replace replace

foreach x in Devento Dattack Dclash Dgue_alt Dpar_alt evento_pc ktotal_pc{
	ivreghdfe `x' $iv_level ${if}, $fe $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val 
	sum `e(depvar)' if e(sample)
	if "`x'"=="ktotal_pc" local replace 
	`out' adds(DV mean,r(mean)) ctitle(`x') $add_iv `replace'
	local replace
}

* Table D8: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS.dta", clear

local out outreg2 using "${dpappendix}\D-robustness\09-tableD8", dec(3) tex(frag) nonot nocons nor2

** Column 1:
ivreghdfe lcnbas $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cnbas) $add_iv replace 

** Column 2:
ivreghdfe lcobrs $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(cobrs) $add_iv

** Column 3:
ivreghdfe lirca $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(lirca) $add_iv

** Column 4:
ivreghdfe Dcnbas100 $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcnbas) $add_iv 

** Column 5:
ivreghdfe Dcobrs100 $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dcobrs) $add_iv 

** Column 6:
ivreghdfe Dirca05 $iv_level ${if}, $fe_mm $cluster ffirst
	$F_tax
	$F_roy
	$test_level
	$p_val
	`out' ctitle(Dirca) $add_iv 

* Table D9: --------------------------------------------------------------------

use "${dpwork}\ESTIMATIONS-TERM.dta", clear

gen target=0

//2001-2003: Chiriguana y San Antero

replace target=1 if codmpio==20178&period==1 //Chiriguana
replace target=1 if codmpio==23672&period==1 //San Antero

//2004-2007: Chiriguana, Castilla, Carbon en Guajira y Cesar

replace target=1 if (coddepto==20|coddepto==44)&period==2 //Todo Cesar y Guajira
replace target=1 if codmpio==50150&period==2 //Castilla la Nueva 

//2008-2011:

replace target=1 if codmpio==44035&period==3 //Albania
replace target=1 if codmpio==81001&period==3 //Arauca
replace target=1 if codmpio==41016&period==3 // Aipe
replace target=1 if codmpio==20045&period==3 // Becerril
replace target=1 if codmpio==50150&period==3 //Castilla la Nueva 
replace target=1 if codmpio==20178&period==3 // Chiriguana
replace target=1 if codmpio==20250&period==3 // El Paso
replace target=1 if codmpio==44378&period==3 // Hatonuevo
replace target=1 if codmpio==20400&period==3 // La Jagua
replace target=1 if codmpio==44560&period==3 // Manaure
replace target=1 if codmpio==85139&period==3 // Mani
replace target=1 if codmpio==41001&period==3 // Neiva
replace target=1 if codmpio==44001&period==3 // Riohacha
replace target=1 if codmpio==23672&period==3 // San Antero
replace target=1 if codmpio==85410&period==3 // Tauramena
replace target=1 if codmpio==44847&period==3 // Uribia
replace target=1 if codmpio==50001&period==3 // Villavicencio
replace target=1 if codmpio==85001&period==3 // Yopal
replace target=1 if codmpio==44430&period==3 // Maicao
replace target=1 if codmpio==70820&period==3 // Tolu
replace target=1 if codmpio==70001&period==3 // Sincelejo
replace target=1 if codmpio==52835&period==3 // Tumaco
replace target=1 if codmpio==50568&period==3 // Puerto Gaitan
replace target=1 if codmpio==73449&period==3 // Melgar
replace target=1 if codmpio==44078&period==3 // Barrancas
replace target=1 if codmpio==47189&period==3 // Cienaga
replace target=1 if codmpio==85010&period==3 // Aguazul

local out outreg2 using "${dpappendix}\D-robustness\10-tableD9", dec(3) tex(frag) nonot nocons nor2 drop(target)

** Column 1:
ivreghdfe alcalde $iv_period target ${if_period}, $fe_period $cluster_period 	///
		ffirst 	
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(D_mayor) $add_iv replace

** Column 2:
ivreghdfe alcalde_sum $iv_period target ${if_period}, $fe_period 				///
		$cluster_period ffirst	
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(sum_mayor) $add_iv  

** Column 3:
ivreghdfe alcalde_1 $iv_period target ${if_period}, $fe_period $cluster_period 	///
		ffirst 	
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(D_mayor_spend) $add_iv  

** Column 4:
ivreghdfe alcalde_2 $iv_period target ${if_period}, $fe_period $cluster_period 	///
		ffirst 	
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(D_mayor_pol) $add_iv  

** Column 5:
ivreghdfe alcalde_3 $iv_period target ${if_period}, $fe_period $cluster_period 	///
		ffirst 	
	$F_tax
	$F_roy
	$test_log
	$p_val
	`out' ctitle(D_mayor_other) $add_iv    


cap graph drop *
